/**
 * 
 */
package com.witframework.components;

import org.apache.commons.lang.StringUtils;
import org.extremecomponents.table.bean.Column;
import org.extremecomponents.table.core.AutoGenerateColumns;
import org.extremecomponents.table.core.TableModel;


/**
 * @author wuxinyang
 * Jun 23, 2009 11:54:20 AM
 * 
 */
public class AutoGenerateColumnsImpl implements AutoGenerateColumns {
	
	public void addColumns(TableModel model) {		
		String columns=model.getTableHandler().getTable().getAttributeAsString("columns");
		String titles=model.getTableHandler().getTable().getAttributeAsString("titles");
		String[] columnNames=StringUtils.split(columns,",");
		String[] columnTitles=StringUtils.split(titles,",");		
		Column column = new Column(model);	
		column.setProperty("checkbox");
		column.setTitle("");		
		column.setCell("display");
		column.setSortable(false);
		column.setWidth("5%");
		column.setViewsAllowed("html");
		model.getColumnHandler().addAutoGenerateColumn(column);
		int i=0;		
		for(String name:columnNames){
			column = new Column(model);	
			column.setProperty(name);
			if(columnTitles.length>i)
				column.setTitle(columnTitles[i]);
			else
				column.setTitle(name);
			column.setCell("display");
			model.getColumnHandler().addAutoGenerateColumn(column);
			i++;
		}
	}

}
